package topt_12z.logging;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Formatter;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;

//This custom formatter formats parts of a log record to a single line
public class LogFormatter extends Formatter {
	// This method is called for every log records
	public String format(LogRecord rec) {
		StringBuffer buf = new StringBuffer();
		if (rec.getLevel().intValue() >= Level.WARNING.intValue()) {
			buf.append("!!!!");
			buf.append(rec.getLevel());
		} else {
			buf.append(rec.getLevel());
		}
		buf.append(" - ");
		buf.append(rec.getSourceClassName());
		buf.append(".");
		buf.append(rec.getSourceMethodName());
		buf.append(": ");
		buf.append(formatMessage(rec));
		buf.append("\n");
		return buf.toString();
	}

	// moze sie pozniej przyda
	@SuppressWarnings("unused")
	private String calcDate(Long millisecs) {
		SimpleDateFormat date_format = new SimpleDateFormat("MMM dd,yyyy HH:mm");
		Date resultdate = new Date(millisecs);
		return date_format.format(resultdate);
	}

	// This method is called just after the handler using this
	// formatter is created
	public String getHead(Handler h) {
		return "Simulation start Date:" + (new Date()) + "\n";
	}

	// This method is called just after the handler using this
	// formatter is closed
	public String getTail(Handler h) {
		return "Simulation end Date:" + (new Date()) + "\n";
	}
}